#!/usr/bin/env python3
from selenium import webdriver
from time import sleep
from multiprocessing import Process


def main(username,password):
    driver = webdriver.Chrome()
    driver.get("http://www.cimo.cn/")
    js = '''
    var token = $('input[name=_token]').val();
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("POST","login",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("username='''+username+'''&password='''+password+'''&_token="+token);
    '''
    driver.execute_script(js)
    sleep(1)
    driver.get("http://www.cimo.cn/safetycontest/random-questions")

    js2 = '''
    setInterval(function(){
        var a = null;
        a = document.getElementsByClassName("weui-dialog__btn primary")[0];
        if(a != null)
            a.click();
    },1000)
    '''
    driver.execute_script(js2)

with open("account.txt","r") as f:
    for count in f.readlines():
        username,password = count.split()
        p = Process(target=main,args=(username,password))
        p.start()
